import React from 'react';

// 引入自带的lazy方法：以懒加载的形式引入组件的方法
// Suspense是一个组件：指定加载组件时的动画
import { lazy, Suspense } from "react"

import { Route, Redirect, Switch } from 'react-router-dom'

// 引入加载组件
import Loading from '@/components/Loading'

// 懒加载的形式引入登陆页面
let Login = lazy(() => import('@/views/login/Index'))
let Dashboard = lazy(() => import('@/views/dashboard/Dashboard'))
const Index = () => {
    return (
        // Suspense:路由匹配的组件未显示前，先显示Loading组件
        <Suspense fallback={<Loading></Loading>}>
            <Switch>
                <Route path='/login' component={Login}></Route>
                <Route path='/dashboard' component={Dashboard}></Route>
                <Redirect from='/' to='/login' exact></Redirect>
            </Switch>
        </Suspense>
    );
}

export default Index;
